package com.aaa.controller.fpa;

import com.aaa.aspect.LogMonitor;
import com.aaa.controller.BaseController;
import com.aaa.entity.PageSortEntity;
import com.aaa.entity.Result;
import com.aaa.entity.fpa.ResultDiv;
import com.aaa.entity.fpa.TestResultFpa;
import com.aaa.entity.fpa.ViewTestResultFpa;
import com.aaa.entity.mht.TestResultMht;
import com.aaa.service.fpa.ViewTestResultFpaService;

import com.github.pagehelper.Page;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.servlet.ModelAndView;

import javax.annotation.Resource;

import java.util.List;
import java.util.Map;

/**
 * (ViewTestResultFpa)表控制层
 *
 * @author
 * @since 2022-09-06 10:00:04
 */
@RestController
@RequestMapping("viewTestResultFpa")
public class ViewTestResultFpaController extends BaseController {
    /**
     * 服务对象
     */
    @Resource
    private ViewTestResultFpaService viewTestResultFpaService;
    Result result = new Result();

    @RequestMapping("toShowTestResultFpa.do")
    public ModelAndView toShowTestResultFpa(ModelAndView modelAndView) {
        modelAndView.setViewName("viewTestResultFpa");
        return modelAndView;
    }

    @RequestMapping("toReportFormsFpa.do")
    public ModelAndView toReportFormsFpa(ModelAndView modelAndView) {
        modelAndView.setViewName("reportFormsFpa");
        return modelAndView;
    }

    /**
     * 分页查询
     *
     * @param viewTestResultFpa 筛选条件
     * @return 查询结果
     */

    @RequestMapping("queryByPage.do")
    public Result queryByPage(PageSortEntity pageSortEntity, ViewTestResultFpa viewTestResultFpa) {
        Page page = viewTestResultFpaService.queryByPage(pageSortEntity, viewTestResultFpa);
        return success(page.getResult(), page.getTotal());
    }

    /**
     * @param
     * @return Result
     * @description: 根据id查询对应信息
     */

    @RequestMapping("queryResultById.do")
    public Result queryResultById(ViewTestResultFpa viewTestResultFpa) {

        List<ViewTestResultFpa> viewTestResultFpas = viewTestResultFpaService.queryRequestById(viewTestResultFpa);
        ViewTestResultFpa viewTestResultFpa1 = viewTestResultFpas.get(0);
        return success(viewTestResultFpa1);
    }

    @RequestMapping(method = RequestMethod.POST, value = "queryResultToReport.do")
    public Result queryResultToReport() {
        Map map = viewTestResultFpaService.queryAllPlanFpa();
        return success(map);
    }


    /**
     * @param
     * @return Result
     * @description: 查询所有数据 报表统计
     */
    @RequestMapping("colorCount.do")
    public Result colorCount() {
        Map<String, Integer> map = this.viewTestResultFpaService.queryAllPlanFpa();
        result.setData(map);
        return success(result);
    }


    /**
     * @param
     * @return
     * @description: 删除
     */
    @LogMonitor
    @RequestMapping("deleteResultFpa.do")
    public Result delete(int[] testerId) {

        boolean b = viewTestResultFpaService.deleteById(testerId);
        boolean Id = viewTestResultFpaService.deleteByTesterId(testerId);
        if (b && Id) {
            return success("删除成功");
        }
        return fail("删除失败");
    }

    /**
     * @param
     * @description: 查询所有数据 报表统计
     */
    @RequestMapping("divId.do")
    public Result resultDiv(Integer id) {
        ResultDiv resultDivs = this.viewTestResultFpaService.queryAllResultDiv(id);
        return success(resultDivs);

    }

    //查询测试结果到查看详情
    @RequestMapping(method = RequestMethod.GET, value = "queryTestResultById.do")
    public Result queryTestResultById(PageSortEntity pageSortEntity, TestResultFpa testResultFpa){
        Page page = viewTestResultFpaService.queryTestResultById(pageSortEntity, testResultFpa);
        return success(page.getResult(),page.getTotal());
    }



}

